package com.cnap.multiclouldmgmt.model;

import com.alibaba.fastjson.JSONObject;
import com.cnap.multiclouldmgmt.model.enums.CloudVendorsEnum;
import com.cnap.multiclouldmgmt.util.CnapCloudMgmtConstants;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;
/**
 * 集群基础信息
 * @author dyq
 */
@ApiModel(value = "com.cnap.multiclouldmgmt.model.K8sClusterInfoModel",description = "集群中各个组件的基本信息")
public class K8sClusterInfoModel {

    //accountName
    @ApiModelProperty(value = "accountName")
    private String accountName= "1";

    //集群名称
    @ApiModelProperty(value = "集群名称")
    private String k8sClusterName;

    //集群ip
    @ApiModelProperty(value = "集群ip")
    private String k8sClusterIp;

    //集群所属区域
    @ApiModelProperty(value = "集群所属区域")
    private String k8sClusterLocation;

    //集群所属云服务商
    @ApiModelProperty(value = "集群所属云服务商")
    private String cloudVendor;


    //集群所属云服务商cloudType
    @ApiModelProperty(value = "集群所属云服务商cloudType")
    private String cloudType;

    //集群创建者
    @ApiModelProperty(value = "集群创建者")
    private String createUser;

    public String getCreateUser() {
        return createUser;
    }

    //最大功率
    @ApiModelProperty(value = "最大功率")
    private String pmax;

    //空闲功率
    @ApiModelProperty(value = "空闲功率")
    private String pidle;


    //cpu成本
    @ApiModelProperty(value = "cpu成本")
    private String cpuCost;
    //cpu成本单位
    @ApiModelProperty(value = "cpu成本单位")
    private String cpuCostUnit;


    //硬盘存储成本
    @ApiModelProperty(value = "硬盘存储成本")
    private String diskCost;
    //硬盘存储成本单位
    @ApiModelProperty(value = "硬盘存储成本单位")
    private String diskCostUnit;

    //GPU成本
    @ApiModelProperty(value = "GPU成本")
    private String gpuCost;
    //GPU成本单位
    @ApiModelProperty(value = "GPU成本单位")
    private String gpuCostUnit;

    //文件存储成本
    @ApiModelProperty(value = "文件存储成本")
    private String fileCost;
    //文件存储成本单位
    @ApiModelProperty(value = "文件存储成本单位")
    private String fileCostUnit;

    //FPGA成本
    @ApiModelProperty(value = "FPGA成本")
    private String fpgaCost;
    //FPGA成本单位
    @ApiModelProperty(value = "FPGA成本单位")
    private String fpgaCostUnit;

    //网络计费方式
    @ApiModelProperty(value = "网络计费方式")
    private String netCostType;
    //网络计费成本
    @ApiModelProperty(value = "固定带宽成本")
    private String netCost;
    //网络计费单位
    @ApiModelProperty(value = "网络计费单位")
    private String netCostUnit;

    //存放在数据库里面的这些信息的json
    @ApiModelProperty(value = "存放在数据库里面的这些信息的json")
    private String clusterInfoJson;

    //vpcid,用于区分云里面的不同vpc
    @ApiModelProperty(value = "vpcid,用于区分云里面的不同vpc")
    private String vpcId = "123456";

    //regionId
    @ApiModelProperty(value = "regionId")
    private String regionId;

    //zoneId
    @ApiModelProperty(value = "zoneId")
    private String zoneId;

    //集群类型，cpu或者GPU
    @ApiModelProperty(value = "集群类型，cpu或者GPU")
    private String arch;

    /**
     * get
     *
     * @return AccountName
     */
    public String getAccountName() {
        return accountName;
    }

    /**
     * set
     *
     * @param accountName accountName
     */
    public void setAccountName(String accountName) {
        this.accountName = accountName;
    }

    /**
     * get
     *
     * @return Arch
     */
    public String getArch() {

        if (StringUtils.isEmpty(arch)){

            if (StringUtils.endsWithIgnoreCase(k8sClusterName, CnapCloudMgmtConstants.ARCH_GPU)){
                arch = CnapCloudMgmtConstants.ARCH_GPU;
            }else {
                arch = CnapCloudMgmtConstants.ARCH_CPU;
            }
        }

        return arch;
    }

    /**
     * set
     *
     * @param arch arch
     */
    public void setArch(String arch) {
        this.arch = arch;
    }

    /**
     * get
     *
     * @return RegionId
     */
    public String getRegionId() {
        return regionId;
    }

    /**
     * set
     *
     * @param regionId regionId
     */
    public void setRegionId(String regionId) {
        this.regionId = regionId;
    }

    /**
     * get
     *
     * @return ZoneId
     */
    public String getZoneId() {
        return zoneId;
    }

    /**
     * set
     *
     * @param zoneId zoneId
     */
    public void setZoneId(String zoneId) {
        this.zoneId = zoneId;
    }
    /**
     * 从json中获取种种数据
     * @return
     */
    public String getClusterInfoJson() {

        if (StringUtils.isEmpty(clusterInfoJson)){

            Map<String,String> infoMap = new HashMap<>();
            infoMap.put("pmax",getPmax());
            infoMap.put("pidle",getPidle());
            infoMap.put("cpuCost",getCpuCost());
            infoMap.put("cpuCostUnit",getCpuCostUnit());
            infoMap.put("diskCost",getDiskCost());
            infoMap.put("diskCostUnit",getDiskCostUnit());
            infoMap.put("gpuCost",getGpuCost());
            infoMap.put("gpuCostUnit",getGpuCostUnit());
            infoMap.put("fileCost",getFileCost());
            infoMap.put("fileCostUnit",getFileCostUnit());
            infoMap.put("fpgaCost",getFpgaCost());
            infoMap.put("fpgaCostUnit",getFpgaCostUnit());
            infoMap.put("netCostType",getNetCostType());
            infoMap.put("netCost",getNetCost());
            infoMap.put("netCostUnit",getNetCostUnit());

            clusterInfoJson = JSONObject.toJSONString(infoMap);
        }

        return clusterInfoJson;
    }

    public String getPmax() {

        if (StringUtils.isEmpty(pmax)
                &&StringUtils.isNotEmpty(clusterInfoJson)){

            pmax = (String) JSONObject.parseObject(clusterInfoJson, Map.class).get("pmax");
        }

        return pmax;
    }

    public String getPidle() {

        if (StringUtils.isEmpty(pidle)
                &&StringUtils.isNotEmpty(clusterInfoJson)){

            pidle = (String) JSONObject.parseObject(clusterInfoJson, Map.class).get("pidle");
        }

        return pidle;
    }

    public String getCpuCost() {

        if (StringUtils.isEmpty(cpuCost)
                &&StringUtils.isNotEmpty(clusterInfoJson)){

            cpuCost = (String) JSONObject.parseObject(clusterInfoJson, Map.class).get("cpuCost");
        }

        return cpuCost;
    }

    public String getCpuCostUnit() {

        if (StringUtils.isEmpty(cpuCostUnit)
                &&StringUtils.isNotEmpty(clusterInfoJson)){

            cpuCostUnit = (String) JSONObject.parseObject(clusterInfoJson, Map.class).get("cpuCostUnit");
        }

        return cpuCostUnit;
    }

    public String getDiskCost() {

        if (StringUtils.isEmpty(diskCost)
                &&StringUtils.isNotEmpty(clusterInfoJson)){

            diskCost = (String) JSONObject.parseObject(clusterInfoJson, Map.class).get("diskCost");
        }

        return diskCost;
    }

    public String getDiskCostUnit() {

        if (StringUtils.isEmpty(diskCostUnit)
                &&StringUtils.isNotEmpty(clusterInfoJson)){

            diskCostUnit = (String) JSONObject.parseObject(clusterInfoJson, Map.class).get("diskCostUnit");
        }

        return diskCostUnit;
    }

    public String getGpuCost() {

        if (StringUtils.isEmpty(gpuCost)
                &&StringUtils.isNotEmpty(clusterInfoJson)){

            gpuCost = (String) JSONObject.parseObject(clusterInfoJson, Map.class).get("gpuCost");
        }

        return gpuCost;
    }

    public String getGpuCostUnit() {

        if (StringUtils.isEmpty(gpuCostUnit)
                &&StringUtils.isNotEmpty(clusterInfoJson)){

            gpuCostUnit = (String) JSONObject.parseObject(clusterInfoJson, Map.class).get("gpuCostUnit");
        }

        return gpuCostUnit;
    }

    public String getFileCost() {

        if (StringUtils.isEmpty(fileCost)
                &&StringUtils.isNotEmpty(clusterInfoJson)){

            fileCost = (String) JSONObject.parseObject(clusterInfoJson, Map.class).get("fileCost");
        }

        return fileCost;
    }

    public String getFileCostUnit() {

        if (StringUtils.isEmpty(fileCostUnit)
                &&StringUtils.isNotEmpty(clusterInfoJson)){

            fileCostUnit = (String) JSONObject.parseObject(clusterInfoJson, Map.class).get("fileCostUnit");
        }

        return fileCostUnit;
    }

    public String getFpgaCost() {

        if (StringUtils.isEmpty(fpgaCost)
                &&StringUtils.isNotEmpty(clusterInfoJson)){

            fpgaCost = (String) JSONObject.parseObject(clusterInfoJson, Map.class).get("fpgaCost");
        }

        return fpgaCost;
    }

    public String getFpgaCostUnit() {

        if (StringUtils.isEmpty(fpgaCostUnit)
                &&StringUtils.isNotEmpty(clusterInfoJson)){

            fpgaCostUnit = (String) JSONObject.parseObject(clusterInfoJson, Map.class).get("fpgaCostUnit");
        }

        return fpgaCostUnit;
    }

    public String getNetCostType() {

        if (StringUtils.isEmpty(netCostType)
                &&StringUtils.isNotEmpty(clusterInfoJson)){

            netCostType = (String) JSONObject.parseObject(clusterInfoJson, Map.class).get("netCostType");
        }

        return netCostType;
    }

    public String getNetCost() {

        if (StringUtils.isEmpty(netCost)
                &&StringUtils.isNotEmpty(clusterInfoJson)){

            netCost = (String) JSONObject.parseObject(clusterInfoJson, Map.class).get("netCost");
        }

        return netCost;
    }

    public String getNetCostUnit() {

        if (StringUtils.isEmpty(netCostUnit)
                &&StringUtils.isNotEmpty(clusterInfoJson)){

            netCostUnit = (String) JSONObject.parseObject(clusterInfoJson, Map.class).get("netCostUnit");
        }

        return netCostUnit;
    }

    /**
     * get
     *
     * @return K8sClusterName
     */
    public String getK8sClusterName() {
        return k8sClusterName;
    }

    /**
     * set
     *
     * @param k8sClusterName k8sClusterName
     */
    public void setK8sClusterName(String k8sClusterName) {
        this.k8sClusterName = k8sClusterName;
    }

    /**
     * get
     *
     * @return K8sClusterIp
     */
    public String getK8sClusterIp() {
        return k8sClusterIp;
    }

    /**
     * set
     *
     * @param k8sClusterIp k8sClusterIp
     */
    public void setK8sClusterIp(String k8sClusterIp) {
        this.k8sClusterIp = k8sClusterIp;
    }

    /**
     * get
     *
     * @return K8sClusterLocation
     */
    public String getK8sClusterLocation() {
        return k8sClusterLocation;
    }

    /**
     * set
     *
     * @param k8sClusterLocation k8sClusterLocation
     */
    public void setK8sClusterLocation(String k8sClusterLocation) {
        this.k8sClusterLocation = k8sClusterLocation;
    }

    /**
     * get
     *
     * @return CloudVendor
     */
    public String getCloudVendor() {
        return cloudVendor;
    }

    /**
     * set
     *
     * @param cloudVendor cloudVendor
     */
    public void setCloudVendor(String cloudVendor) {
        this.cloudVendor = cloudVendor;
    }

    /**
     * set
     *
     * @param createUser createUser
     */
    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    /**
     * set
     *
     * @param pmax pmax
     */
    public void setPmax(String pmax) {
        this.pmax = pmax;
    }

    /**
     * set
     *
     * @param pidle pidle
     */
    public void setPidle(String pidle) {
        this.pidle = pidle;
    }

    /**
     * set
     *
     * @param cpuCost cpuCost
     */
    public void setCpuCost(String cpuCost) {
        this.cpuCost = cpuCost;
    }

    /**
     * set
     *
     * @param cpuCostUnit cpuCostUnit
     */
    public void setCpuCostUnit(String cpuCostUnit) {
        this.cpuCostUnit = cpuCostUnit;
    }

    /**
     * set
     *
     * @param diskCost diskCost
     */
    public void setDiskCost(String diskCost) {
        this.diskCost = diskCost;
    }

    /**
     * set
     *
     * @param diskCostUnit diskCostUnit
     */
    public void setDiskCostUnit(String diskCostUnit) {
        this.diskCostUnit = diskCostUnit;
    }

    /**
     * set
     *
     * @param gpuCost gpuCost
     */
    public void setGpuCost(String gpuCost) {
        this.gpuCost = gpuCost;
    }

    /**
     * set
     *
     * @param gpuCostUnit gpuCostUnit
     */
    public void setGpuCostUnit(String gpuCostUnit) {
        this.gpuCostUnit = gpuCostUnit;
    }

    /**
     * set
     *
     * @param fileCost fileCost
     */
    public void setFileCost(String fileCost) {
        this.fileCost = fileCost;
    }

    /**
     * set
     *
     * @param fileCostUnit fileCostUnit
     */
    public void setFileCostUnit(String fileCostUnit) {
        this.fileCostUnit = fileCostUnit;
    }

    /**
     * set
     *
     * @param fpgaCost fpgaCost
     */
    public void setFpgaCost(String fpgaCost) {
        this.fpgaCost = fpgaCost;
    }

    /**
     * set
     *
     * @param fpgaCostUnit fpgaCostUnit
     */
    public void setFpgaCostUnit(String fpgaCostUnit) {
        this.fpgaCostUnit = fpgaCostUnit;
    }

    /**
     * set
     *
     * @param netCostType netCostType
     */
    public void setNetCostType(String netCostType) {
        this.netCostType = netCostType;
    }

    /**
     * set
     *
     * @param netCost netCost
     */
    public void setNetCost(String netCost) {
        this.netCost = netCost;
    }

    /**
     * set
     *
     * @param netCostUnit netCostUnit
     */
    public void setNetCostUnit(String netCostUnit) {
        this.netCostUnit = netCostUnit;
    }

    /**
     * set
     *
     * @param clusterInfoJson clusterInfoJson
     */
    public void setClusterInfoJson(String clusterInfoJson) {
        this.clusterInfoJson = clusterInfoJson;
    }

    /**
     * get
     *
     * @return VpcId
     */
    public String getVpcId() {
        return vpcId;
    }

    /**
     * set
     *
     * @param vpcId vpcId
     */
    public void setVpcId(String vpcId) {
        this.vpcId = vpcId;
    }

    /**
     * get
     *
     * @return CloudType
     */
    public String getCloudType() {

        if (StringUtils.isEmpty(cloudType)){
            cloudType = CloudVendorsEnum.getCloudeTypeByDescribe(cloudVendor);
        }

        return cloudType;
    }

    /**
     * set
     *
     * @param cloudType cloudType
     */
    public void setCloudType(String cloudType) {
        this.cloudType = cloudType;
    }
}
